package com.lyf.design.practice.theory.create.singleton;

import org.junit.Test;

import java.util.concurrent.TimeUnit;

/**
 * @author LYF
 * @date 2022/6/19
 */
public class SingleTests {
    /**
     * 模拟多线程创建问题-Singleton2
     */
    @Test
    public void test1(){
        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                Singleton2 singleton2 = Singleton2.getInstance();
                System.out.println(singleton2);
            }).start();
        }
        // 保证主线程不关闭，看到输出结果
        try {
            TimeUnit.SECONDS.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }



}
